package com.sz.app.oss.api.common.project;

import com.sz.app.oss.constants.Permissions;
import com.sz.biz.app.web.BaseController;
import com.sz.biz.common.constants.MessagesCodes;
import com.sz.biz.common.project.dto.*;
import com.sz.biz.common.project.entity.Project;
import com.sz.biz.common.project.entity.ProjectAudit;
import com.sz.biz.common.project.entity.ProjectFile;
import com.sz.biz.common.project.entity.ProjectQuestion;
import com.sz.biz.common.platform.service.PlatformCompanyService;
import com.sz.biz.common.project.service.ProjectAuditService;
import com.sz.biz.common.project.service.ProjectCompanyService;
import com.sz.biz.common.project.service.ProjectFileService;
import com.sz.biz.common.project.service.ProjectService;
import com.sz.common.base.dto.QueryParams;
import com.sz.common.base.dto.ResultDto;
import com.sz.common.base.utils.StringUtils;
import com.sz.common.core.service.PrincipalUtils;
import com.sz.common.core.system.service.OrgService;
import com.sz.common.core.system.service.UserService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * Function: 物流项目管理 <br>
 * Author: wentao.chang <br>
 * Date: 2017-07-13 10:18:00
 */
@RestController
@RequestMapping("${api}/biz/logistics/projects")
@Api(description = " ", tags = "056-01、物流项目管理")
public class ProjectController extends BaseController {

    @Autowired
    private ProjectService projectService;

    @Autowired
    private ProjectFileService projectFileService;

    @Autowired
    private ProjectAuditService projectAuditService;

    @Autowired
    private ProjectCompanyService projectCompanyService;
    @Autowired
    private PlatformCompanyService platformCompanyService;

    @Autowired
    private UserService userService;

    @Autowired
    private OrgService orgService;

    @ApiOperation(value = "项目列表--新增项目", notes = "项目列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "starttime", value = "开始时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endtime", value = "结束时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "项目状态：-1全部 1.草稿 2.待初审3.待终审 4已立项 5已结项 6已关闭",
                    dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "companyname", value = "干系企业", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "project", value = "项目名称", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "分页", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", dataType = "int",
                    paramType = "query"),
            @ApiImplicitParam(name = "sort", value = "排序的字段", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "asc", value = "排序方式", dataType = "boolean", paramType = "query",
                    defaultValue = "true")})
    @RequestMapping(value = "", method = {RequestMethod.GET})
    @RequiresPermissions(Permissions.BIZ_MGT_BASE_PROJECT)
    public ResultDto queryNormal(@RequestParam(required = false) String starttime,
                                 @RequestParam(required = false) String endtime,
                                 @RequestParam(required = false, defaultValue = "-1") int status,
                                 @RequestParam(required = false) String companyname,
                                 @RequestParam(required = false) String project,
                                 @RequestParam(required = false, defaultValue = "1") int pageIndex,
                                 @RequestParam(required = false, defaultValue = "10") int pageSize,
                                 @RequestParam(required = false) String sort,
                                 @RequestParam(required = false, defaultValue = "true") Boolean asc) {
        project = StringUtils.replaceSqlPattern(project);
        QueryParams params = new QueryParams(pageSize, pageIndex, project, sort, asc);
        params.put("starttime", starttime);
        params.put("endtime", endtime);
        params.put("biztype", "1");
        params.put("status", status);
        params.put("companyname", companyname);

        return projectService.findByFilter(params);
    }

    @ApiOperation(value = "项目列表--审核项目", notes = "项目列表", position = -1)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "starttime", value = "开始时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endtime", value = "结束时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "项目状态：-1全部 2.待初审3.待终审 4已立项 5已结项 6已关闭",
                    dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "companyname", value = "干系企业", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "project", value = "项目名称", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "分页", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "sort", value = "排序的字段", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "asc", value = "排序方式", dataType = "boolean", paramType = "query",
                    defaultValue = "true")})
    @RequestMapping(value = "/approval", method = {RequestMethod.GET})
    @RequiresPermissions(Permissions.BIZ_MGT_BASE_PROJECT_APPROVAL)
    public ResultDto queryAudited(@RequestParam(required = false) String starttime,
                                  @RequestParam(required = false) String endtime,
                                  @RequestParam(required = false, defaultValue = "-1") int status,
                                  @RequestParam(required = false) String companyname,
                                  @RequestParam(required = false) String project,
                                  @RequestParam(required = false, defaultValue = "1") int pageIndex,
                                  @RequestParam(required = false, defaultValue = "10") int pageSize,
                                  @RequestParam(required = false) String sort,
                                  @RequestParam(required = false, defaultValue = "true") Boolean asc) {
        project = StringUtils.replaceSqlPattern(project);
        QueryParams params = new QueryParams(pageSize, pageIndex, project, sort, asc);
        params.put("starttime", starttime);
        params.put("endtime", endtime);
        params.put("biztype", "1");
        params.put("status", status);
        params.put("companyname", companyname);
        params.put("fromaudit", true);
        return projectService.findByFilter(params);
    }

    @ApiOperation(value = "项目短接口--已立项和已结项的项目", notes = "项目短接口--已立项和已结项的项目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "includeClosed", value = "包含已關閉", dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "project", value = "项目名称", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "orderType", value = "订单类型", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "sellerId", value = "销售方id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "purchaserId", value = "采购方id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "分页", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", dataType = "int", paramType = "query")
    })
    @RequestMapping(value = "/short", method = {RequestMethod.GET})
    public ResultDto queryAudited(
            @RequestParam(required = false) String project,
            @RequestParam(required = false) String orderType,
            @RequestParam(required = false,defaultValue = "false") boolean includeClosed,
            @RequestParam(required = false, defaultValue = "0") int sellerId,
            @RequestParam(required = false, defaultValue = "0") int purchaserId,
            @RequestParam(required = false, defaultValue = "1") int pageIndex,
            @RequestParam(required = false, defaultValue = "10") int pageSize) {
        project = StringUtils.replaceSqlPattern(project);
        QueryParams params = new QueryParams(pageSize, pageIndex, project, "name", true);
        params.put("orderType", orderType);
        params.put("sellerId", sellerId);
        params.put("bizTypeCode", "1");
        params.put("purchaserId", purchaserId);
        params.put("includeClosed", includeClosed);
        return projectService.findShortByFilter(params);
    }


    @ApiOperation(value = "新增项目", notes = "新增项目")
    @RequestMapping(value = "", method = {RequestMethod.POST})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "issubmit", value = "是否提交", dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "projectDto", value = "保存的数据\r\n" +
                    "name,code,bizTypeCode,orgId,\n" +
                    "companys :[{ type(1供应商2客户3平台), companyId}],\n" +
                    "files :[{ fileId , remark }],\n" +
                    "profile,value,risk\n",
                    required = true, dataType = "ProjectDto", paramType = "body")})
    @RequiresPermissions(Permissions.BIZ_MGT_BASE_PROJECT)
    public ResultDto save(@RequestBody ProjectDto projectDto, @RequestParam boolean issubmit) {
        projectDto.setBizTypeCode("1");
        int id = projectService.save(projectDto, issubmit);
        ResultDto resultDto = issubmit ? getSubmitSuccessDto(MessagesCodes.MODULE_TRADE_PROJECT) : getSaveSuccessDto(MessagesCodes.MODULE_TRADE_PROJECT);
        resultDto.setData(id);
        return resultDto;
    }

    @ApiOperation(value = "修改项目数据", notes = "修改项目数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "int", paramType = "path", required = true),
            @ApiImplicitParam(name = "issubmit", value = "是否提交", dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "projectDto", value = "修改的数据\r\n" +
                    "name,code,bizTypeCode,orgId,\n" +
                    "companys :[{ type(1供应商2客户3平台), companyId}],\n" +
                    "files :[{ fileId,name,remark }],\n" +
                    "profile,value,risk\n",
                    required = true, dataType = "ProjectDto", paramType = "body")})
    @RequiresPermissions(Permissions.BIZ_MGT_BASE_PROJECT)
    @RequestMapping(value = "/{projectId}", method = {RequestMethod.PUT})
    public ResultDto update(@RequestBody ProjectDto projectDto, @PathVariable int projectId, @RequestParam boolean issubmit) {
        projectDto.setBizTypeCode("1");
        projectService.update(projectId, projectDto, issubmit);
        return issubmit ? getSubmitSuccessDto(MessagesCodes.MODULE_TRADE_PROJECT) : getUpdateSuccessDto(MessagesCodes.MODULE_TRADE_PROJECT);
    }

    @ApiOperation(value = "删除项目", notes = "删除项目<br>权限：" + Permissions.BIZ_MGT_BASE_PROJECT)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "项目ids", required = true, dataType = "List", paramType = "body")})
    @RequestMapping(value = "/deletions", method = {RequestMethod.POST})
    @RequiresPermissions(Permissions.BIZ_MGT_BASE_PROJECT)
    public
    @ResponseBody
    ResultDto batchDeleteByIds(@RequestBody List<Integer> ids) {
        projectService.deleteByIds(ids);
        return this.getDeleteSuccessDto(com.sz.app.oss.constants.MessagesCodes.MODULE_TRADE_PROJECT);
    }

    @ApiOperation(value = "提交项目", notes = "提交项目<br>权限：" + Permissions.BIZ_MGT_BASE_PROJECT)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "项目ids", required = true, dataType = "List", paramType = "body")})
    @RequestMapping(value = "/submitions", method = {RequestMethod.POST})
    @RequiresPermissions(Permissions.BIZ_MGT_BASE_PROJECT)
    public
    @ResponseBody
    ResultDto batchSubmitByIds(@RequestBody List<Integer> ids) {
        projectService.submitByIds(ids);
        return this.getSubmitSuccessDto(com.sz.app.oss.constants.MessagesCodes.MODULE_TRADE_PROJECT);
    }


    @ApiOperation(value = "初审问询", notes = "初审问询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "int", paramType = "path", required = true),
            @ApiImplicitParam(name = "projectQuestion", value = "问题\r\n" +
                    "askContent", required = true, dataType = "ProjectQuestion", paramType = "body")})
    @RequestMapping(value = "/{projectId}/questions", method = {RequestMethod.POST})
    @RequiresPermissions(Permissions.BIZ_MGT_BASE_PROJECT_APPROVAL)
    public ResultDto askAudit(@RequestBody ProjectQuestion projectQuestion, @PathVariable int projectId) {
        int currentUserId = PrincipalUtils.getAccountId();
        projectQuestion.setUserId(currentUserId);
        projectQuestion.setCreateTime(new Date());
        projectQuestion.setProjectId(projectId);
        projectService.addAskQuestion(projectQuestion, projectId);
        return getOperateSuccessDto(MessagesCodes.MODULE_TRADE_PROJECT_REVIEW_ASK_SUCCESS);
    }

    @ApiOperation(value = "初审问询的回复", notes = "审核问询的回复")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "int", paramType = "path", required = true),
            @ApiImplicitParam(name = "questionId", value = "问题id", dataType = "int", paramType = "path", required = true),
            @ApiImplicitParam(name = "projectQuestion", value = "问题\r\n" +
                    "answerContent", required = true, dataType = "ProjectQuestion", paramType = "body")})
    @RequestMapping(value = "/{projectId}/questions/{questionId}", method = {RequestMethod.POST})
    @RequiresPermissions(value = {Permissions.BIZ_MGT_BASE_PROJECT, Permissions.BIZ_MGT_BASE_PROJECT_APPROVAL}, logical = Logical.OR)
    public ResultDto answerAudit(@RequestBody ProjectQuestion projectQuestion, @PathVariable int projectId,
                                 @PathVariable int questionId) {
        int currentUserId = PrincipalUtils.getAccountId();
        projectQuestion.setUserId(currentUserId);
        projectQuestion.setCreateTime(new Date());
        projectQuestion.setProjectId(projectId);
        projectQuestion.setId(questionId);
        projectService.addAskQuestion(projectQuestion, projectId);
        return getOperateSuccessDto(MessagesCodes.MODULE_TRADE_PROJECT_REVIEW_ANSWER_SUCCESS);
    }

    @ApiOperation(value = "初审意见", notes = "初审意见")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "int", paramType = "path", required = true),
            @ApiImplicitParam(name = "projectAudit", value = "初审意见\r\n" +
                    "{type:1.风控2.财务3.运营,msg,isPass}", required = true, dataType = "ProjectAudit", paramType = "body")})
    @RequiresPermissions(Permissions.BIZ_MGT_BASE_PROJECT_APPROVAL)
    @RequestMapping(value = "/{projectId}/firstaudits", method = {RequestMethod.POST})
    public ResultDto firstAudits(@RequestBody ProjectAudit projectAudit, @PathVariable int projectId) {
        projectService.updateFirstAudit(projectId, projectAudit);
        String msg = projectAudit.getIsPass() ?
                MessagesCodes.MODULE_TRADE_PROJECT_REVIEW_SUBMIT_SUCCESS :
                MessagesCodes.MODULE_TRADE_PROJECT_REVIEW_SUBMIT_UNSUCCESS;
        String org = projectAudit.getType() == 1 ? "风控" : (projectAudit.getType() == 2 ? "财务" : "运营");
        return getOperateSuccessDto(msg, new String[]{org});
    }

    @ApiOperation(value = "获取某部门初审信息", notes = "获取某部门初审信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "int", paramType = "path", required = true),
            @ApiImplicitParam(name = "type", value = "type 1.风控 2.财务3.运营", dataType = "int", paramType = "query", required = true)
    })
    @RequiresPermissions(value = {Permissions.BIZ_MGT_BASE_PROJECT, Permissions.BIZ_MGT_BASE_PROJECT_APPROVAL}, logical = Logical.OR)
    @RequestMapping(value = "/{projectId}/firstaudits", method = {RequestMethod.GET})
    public ResultDto auditInfo(@RequestParam int type, @PathVariable int projectId) {
        ProjectAuditInfoDto projectAuditInfoDto = projectAuditService.getProjectAuditInfoDtoByProjectIdAndType(projectId, type);
        ResultDto resultDto = new ResultDto();
        resultDto.setData(projectAuditInfoDto);
        return resultDto;
    }

    @ApiOperation(value = "获取平台公司", notes = "平台公司")
    @RequestMapping(value = "/platcompanys", method = {RequestMethod.GET})
    public ResultDto getPlatCompanys() {
        return new ResultDto(platformCompanyService.findAll());
    }

    @ApiOperation(value = "初审意见汇总", notes = "初审意见汇总")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "project", value = "项目意见{firstAuditMsg:bbbb}", required = true, dataType = "Project", paramType =
                    "body"),
            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "int", paramType = "path", required =
                    true)})
    @RequiresPermissions(Permissions.BIZ_MGT_BASE_PROJECT_APPROVAL)
    @RequestMapping(value = "/firstaudit/{projectId}", method = {RequestMethod.POST})
    public ResultDto addFirstSummary(@RequestBody Project project, @PathVariable int projectId) {
        projectService.updateFirstAuditMsg(projectId, project.getFirstAuditMsg());
        return getOperateSuccessDto(MessagesCodes.MODULE_TRADE_PROJECT_FIRST_AUDIT_MESSAGE_SUCCESS);
    }

    @ApiOperation(value = "终审", notes = "终审")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "finalAuditDto", value = "终审数据dto,终审意见：finalAuditMsg, 是否通过：isPass", required =
                    true, dataType = "Project", paramType =
                    "body"),
            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "int", paramType = "path", required =
                    true)})
    @RequiresPermissions(Permissions.BIZ_MGT_BASE_PROJECT_APPROVAL)
    @RequestMapping(value = "/finalaudit/{projectId}", method = {RequestMethod.POST})
    public ResultDto finalAudit(@RequestBody FinalAuditDto finalAuditDto, @PathVariable int projectId) {
        projectService.updateFinalAuditMsg(projectId, finalAuditDto.getFinalAuditMsg(), finalAuditDto.getIsPass());
        String msg = finalAuditDto.getIsPass() ?
                MessagesCodes.MODULE_TRADE_PROJECT_FINAL_AUDIT_MESSAGE_SUCCESS :
                MessagesCodes.MODULE_TRADE_PROJECT_FINAL_AUDIT_MESSAGE_UNSUCCESS;
        return getOperateSuccessDto(msg);
    }

    @ApiOperation(value = "按照项目id获取基础数据", notes = "项目id获取基础数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "int", paramType = "path", required =
                    true)})
    @RequiresPermissions(value = {Permissions.BIZ_MGT_BASE_PROJECT, Permissions.BIZ_MGT_BASE_PROJECT_APPROVAL}, logical = Logical.OR)
    @RequestMapping(value = "/{projectId}", method = {RequestMethod.GET})
    public ResultDto baseProjectInfo(@PathVariable int projectId) {
        ProjectDto projectDto = projectService.findDtoById(projectId);
        ResultDto resultDto = new ResultDto();
        resultDto.setData(projectDto);
        return resultDto;
    }

    @ApiOperation(value = "项目总结", notes = "项目总结")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "int", paramType = "path", required =
                    true),
            @ApiImplicitParam(name = "project", value = "项目 ：  summary , files{projectId,type,filedId,remark} ", dataType = "ProjectDto", paramType = "body", required =
                    true),
    })
    @RequiresPermissions(Permissions.BIZ_MGT_BASE_PROJECT_APPROVAL)
    @RequestMapping(value = "/baseinfo/{projectId}", method = {RequestMethod.POST})
    public ResultDto baseProjectInfo(@PathVariable int projectId, @RequestBody ProjectDto project) {
        projectService.closeProject(projectId, project);
        return getOperateSuccessDto(MessagesCodes.MODULE_TRADE_PROJECT_SUMMARY_MESSAGE_SUCCESS);
    }

    @ApiOperation(value = "获取项目相关文件", notes = "获取项目相关文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "int", paramType = "path", required =
                    true),
            @ApiImplicitParam(name = "type", value = "文件类型 1项目文件2问询文件3合同文件", dataType = "int", paramType = "query", required =
                    true),
    })
    @RequiresPermissions(value = {Permissions.BIZ_MGT_BASE_PROJECT, Permissions.BIZ_MGT_BASE_PROJECT_APPROVAL}, logical = Logical.OR)
    @RequestMapping(value = "/projectfile/{projectId}", method = {RequestMethod.GET})
    public ResultDto projectFiles(@RequestParam(required = true) int type, @PathVariable int projectId) {
        List<ProjectFileDto> projectFileDtoList = projectFileService.queryByProjectDetail(projectId, type);
        ResultDto resultDto = new ResultDto();
        resultDto.setData(projectFileDtoList);
        return resultDto;
    }

    @ApiOperation(value = "上传文件", notes = "上传项目相关文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "int", paramType = "path",
                    required = true),
            @ApiImplicitParam(name = "type", value = "文件类型1.项目文件2.问询文件3.合同文件", dataType = "int",
                    paramType = "path", required = true)
    })
    @RequiresPermissions(value = {Permissions.BIZ_MGT_BASE_PROJECT, Permissions.BIZ_MGT_BASE_PROJECT_APPROVAL}, logical = Logical.OR)
    @RequestMapping(value = "/projectfile/{projectId}/{type}", method = {RequestMethod.POST})
    public ResultDto uploadProjectFiles(@RequestBody @ApiParam ProjectFile projectFile, @PathVariable int projectId,
                                        @PathVariable int type) {
        projectFile.setProjectId(projectId);
        projectFile.setType(type);
        if (StringUtils.isEmpty(projectFile.getId()) || projectFile.getId() == 0) {
            projectFileService.save(projectFile);
        } else {
            projectFileService.update(projectFile);
        }
        return new ResultDto();
    }

    @ApiOperation(value = "删除合同文件", notes = "删除合同文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "int", paramType = "path",
                    required = true),
            @ApiImplicitParam(name = "id", value = "文件Id", dataType = "int",
                    paramType = "path", required = true)
    })
    @RequiresPermissions(value = {Permissions.BIZ_MGT_BASE_PROJECT, Permissions.BIZ_MGT_BASE_PROJECT_APPROVAL}, logical
            = Logical.OR)
    @RequestMapping(value = "/projectfile/{projectId}/{id}", method = {RequestMethod.DELETE})
    public ResultDto uploadProjectFiles(@PathVariable int projectId,
                                        @PathVariable int id) {
        projectFileService.deleteByIdProjectIdAndType(projectId, id, 3);
        return getOperateSuccessDto(MessagesCodes.MODULE_TRADE_PROJECT_DELETE_FILE_SUCCESS);
    }

    @ApiOperation(value = "当前用户的组织", notes = "当前用户的组织")
    @RequestMapping(value = "/currentUserOrg", method = {RequestMethod.GET})
    public ResultDto getCurrentUserOrg() {
        int accountId = PrincipalUtils.getAccountId();
        List<ProjectUserOrgDto> listUserOrg = projectService.getProjectUserOrg(accountId);
        ResultDto resultDto = new ResultDto();
        resultDto.setData(listUserOrg);
        return resultDto;
    }

    @ApiOperation(value = "搜索干系企业", notes = "搜索干系企业列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "q", value = "干系企业名称或者编码", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "isAudit", value = "是否是審核項目", dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "biztype", value = "业务类型1物流 2贸易", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "分页", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", dataType = "int",
                    paramType = "query"),
            @ApiImplicitParam(name = "sort", value = "排序的字段", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "asc", value = "排序方式", dataType = "boolean", paramType = "query",
                    defaultValue = "true")})
    @RequestMapping(value = "/getprojectcompanys", method = {RequestMethod.GET})
    public ResultDto getProjectCompanys(@RequestParam(required = false) String q,
                                        @RequestParam(required = false, defaultValue = "false") Boolean isAudit,
                                        @RequestParam(required = false, defaultValue = "2") String biztype,
                                        @RequestParam(required = false, defaultValue = "1") int pageIndex,
                                        @RequestParam(required = false, defaultValue = "10") int pageSize,
                                        @RequestParam(required = false) String sort,
                                        @RequestParam(required = false, defaultValue = "true") Boolean asc) {
        q = StringUtils.replaceSqlPattern(q);
        int currentUserId = PrincipalUtils.getAccountId();
        QueryParams params = new QueryParams(pageSize, pageIndex, q, sort, asc);
        params.put("userId", currentUserId);
        params.put("isAudit", isAudit);
        params.put("biztype", biztype);
        return projectCompanyService.findByFilter(params);
    }

    @ApiOperation(value = "获取项目状态", notes = "获取项目状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "int", paramType = "path", required =
                    true)
    })
    @RequestMapping(value = "/getprojectprocesstatus/{projectId}", method = {RequestMethod.GET})
    @RequiresPermissions(value = {Permissions.BIZ_MGT_BASE_PROJECT, Permissions.BIZ_MGT_BASE_PROJECT_APPROVAL}, logical = Logical.OR)
    public ResultDto getProjectProcesStatus(@PathVariable int projectId) {
        ProjectProcessStatusDto dto = projectService.getProjectProcessStatus(projectId);
        ResultDto resultDto = new ResultDto();
        resultDto.setData(dto);
        return resultDto;
    }

    @ApiOperation(value = "异步校验code", notes = "异步校验code")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "项目编码", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "id", value = "项目id 修改时传id 新增时传空", dataType = "int", paramType = "query")})
    @RequestMapping(value = "/checkcode", method = {RequestMethod.GET})
    public ResultDto codeCheck(@RequestParam String code,
                               @RequestParam(required = false, defaultValue = "0") int id) {
        projectService.codeCheck(id, code, "1");
        return new ResultDto();
    }


}
